<script setup>
import {useRoute, useRouter} from 'vue-router'
import { computed} from 'vue'
import {
  Menu as IconMenu,
  UserFilled,
  Grid,
  Promotion
} from '@element-plus/icons-vue'
const route = useRoute()
const router = useRouter()
import {useUserStore} from "@/stores/modules/useUserStore.ts";
const userStore = useUserStore();
const defaultActive = computed(() => route.path)
const logout = ()=>{
  userStore.CLEAR_USERINFO();
  userStore.CLEAR_TOKEN();
  router.push("/login")
}
</script>

<template>
  <el-container>
    <el-aside class="el-aside-open">
      <el-menu
          active-text-color="#ffd04b"
          background-color="#545c64"
          class="el-menu-vertical-demo"
          :default-active="defaultActive"
          text-color="#fff"
          style="height: 100%"
          router
      >
        <el-menu-item index="/home">
          <el-icon>
            <icon-menu/>
          </el-icon>
          <span>首页</span>
        </el-menu-item>

        <el-sub-menu index="1">
          <template #title>
            <el-icon>
              <Grid/>
            </el-icon>
            <span>商品管理</span>
          </template>

          <el-menu-item-group>
            <el-menu-item index="/product">商品列表</el-menu-item>
            <el-menu-item index="/category">分类管理</el-menu-item>
          </el-menu-item-group>

        </el-sub-menu>

        <el-sub-menu index="2">
          <template #title>
            <el-icon>
              <Promotion/>
            </el-icon>
            <span>订单管理</span>
          </template>

          <el-menu-item-group>
            <el-menu-item index="/order">订单列表</el-menu-item>
            <el-menu-item index="/check">验货处理</el-menu-item>
          </el-menu-item-group>

        </el-sub-menu>
        <el-menu-item index="/user">
          <template #title>
            <el-icon>
              <UserFilled/>
            </el-icon>
            <span>用户管理</span>
          </template>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header>
        <div class="navBar">
          <h4>二手交易商城管理系统</h4>

          <div class="navBar-right">
            <el-dropdown>
					    <span class="el-dropdown-link">
					      <el-avatar shape="square" :size="40"
                           src="https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/zhuawaba/5a9f48118166308daba8b6da7e466aab.jpg"></el-avatar>
					    </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>

        </div>
      </el-header>

      <el-main style="padding: 10px;">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<style lang="scss" scoped>

.el-container {
  width: 100%;
  height: 100%;
}

.el-aside-open {
  width: 200px;
}

.container {
  width: calc(100% - 210px);
  height: 100%;

  position: fixed;
  top: 0;
  right: 0;
  z-index: 9;
  transition: all 0.28s;

  &.hidderContainer {
    width: calc(100% - 67px);
  }
}

::v-deep .el-header {
  padding: 0;
}

.navBar {
  width: 100%;
  height: 60px;
  overflow: hidden;
  background-color: #fff;
  box-shadow: 0 1px 1px rgba(0, 21, 41, 0.08);
  padding: 0 16px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  position: relative;
}

.navBar {
  .navBar-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    ::v-deep .navBar-item {
      display: inline-block;
      margin-left: 18px;
      font-size: 22px;
      color: #5a5e66;
      box-sizing: border-box;
      cursor: pointer;
    }
  }
}

</style>
